package org.tang.stock;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

public class TestZF {

	public static void main(String[] args) throws Exception {
		FileReader syzg = new FileReader(new File("D:\\table.csv"));
		BufferedReader buffer = new BufferedReader(syzg);
		ArrayList<Stock> stocks = new ArrayList<Stock>();
		String line = null;
		line = buffer.readLine();
		while ((line = buffer.readLine()) != null) {
			Stock tmp = new Stock(line);
			if (tmp.getVolume() != 0)
				stocks.add(tmp);
		}
		System.out.println("" + stocks.size());
		int sum1 = 0;
		int sum2 = 0;
		int count = 0, count3 = 0;
		double t = 0.0;
		for (int i = 1; i < stocks.size() - 10; i++) {
			sum1 = sum2;
			for (int j = 0; j < 5; j++) {
				sum1 += stocks.get(i + j).getClosePrice();
				sum2 += stocks.get(i + j + 1).getClosePrice();
			}
			int minZF = Integer.MAX_VALUE;
			for (int j = 0; j < 5; j++) {
				if(stocks.get(i+j).getHightPrice() - stocks.get(i+j).getLowPrice() < minZF ){
					minZF = stocks.get(i+j).getHightPrice() - stocks.get(i+j).getLowPrice();
				}
			}
			double or = stocks.get(i).getOpenPrice()*0.995 ;
			if (sum1 > sum2&& or > stocks.get(i).getLowPrice()) {
				count++;
				if(or + minZF*0.7 < stocks.get(i-1).getHightPrice() ){
					count3 ++;
					if(stocks.get(i-1).getOpenPrice() > or + minZF*0.7 )
						t += (stocks.get(i-1).getOpenPrice()*1.0)/or - 1.0026;
					else
						t += (minZF*0.7)/or - 0.0026;
				}else{
					t += stocks.get(i-1).getClosePrice()*1.0/or - 1.0026;
					//System.out.println(stocks.get(i).getDate());
				}
			}
		}
		System.out.println("t = " + t );
		System.out.println("count = " + count + ",count3 = " + count3 + " % = " + count3*1.0/count);
	}

}
